// pages/epi_5/map/mapWork.js
const QQMapWX = require('../../../libs/qqmap-wx-jssdk.js')
const qqmapsdk = new QQMapWX({
    key: "QUOBZ-6G3CW-NHVRP-YJKGG-LFFNE-XTFOX"
})
Page({

    /**
     * 页面的初始数据
     */
    data: {
        mapLongitude:113.324520,
        mapLatitude:23.099994,
        mapScale:16,
        mapMarkers: [{
            id:1, 
            iconPath:'/images/gps.png',
            longitude: 113.324520,
            latitude: 23.099994,
            width: 30,
            height: 30
        }],
        mapLoc: true,
        tab1: true,
        tab2: false,
        getInfo: {
            longitude: 0,
            latitude: 0
        },
        curInfo: {
            longitude: 0,
            latitude: 0,
            speed: 0,
            altitude: 0,
        },
        to: {
            longitude: 102.999594,
            latitude: 25.122284,
        }
    },

    show(e){
        if (e.target.id == 'btn1'){
          this.setData({
              tab1: true,
              tab2: false
          })
        } else {
          this.setData({
              tab1: false,
              tab2: true
          })  
        }
    },
    
    run(e){
        const mapCtx = wx.createMapContext('myMap');
        var that = this;
        switch(e.target.id){
            case "getCL":
                mapCtx.getCenterLocation({
                    success(res){
                        that.setData({
                            "getInfo.longitude": res.longitude,
                            "getInfo.latitude": res.latitude
                        })
                    }
                })
                break
            case "moveTL":
                mapCtx.moveToLocation({
                    latitude: this.data.to.latitude,
                    longitude: this.data.to.longitude, 
                })
                break
            case "getL":
                wx.getLocation({
                    type: 'gcj02',
                    success(res){
                        that.setData({
                            "curInfo.longitude": res.longitude,
                            "curInfo.latitude": res.latitude,
                            "curInfo.speed": res.speed,
                            "curInfo.altitude": res.altitude,
                            "to.longitude": res.longitude,
                            "to.latitude": res.latitude
                        })
                    }
                })
                break
            case "mapSDK":
                qqmapsdk.search({
                    keyword: '酒店',
                    success(res){
                        console.log(res)
                    },
                    fail(res){
                        console.log(res)
                    }
                })
                break
        }
    }
  })